class ProjectsController < ApplicationController
  def index
    @partner= Partner.find(params[:partner_id])
    @projects=@partner.projects
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @projects }
    end
  end
  
  def destroy
    @partner= Partner.find(params[:partner_id])
    @project=@partner.projects.find(params[:id])
    @project.destroy
    respond_to do |format|
      format.html { redirect_to partner_projects_url }
      format.js
#      { head :ok }
    end
  end

  def new
    @project=Project.new
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @project }
    end
  end

  def create
    @partner = Partner.find(params[:partner_id])
    @project = Project.new(params[:project])
    @project.partners << @partner
    respond_to do |format|
      if @project.save
        
        format.html { redirect_to partner_projects_url(:notice => 'Project was successfully created.') }
        format.xml  { render :xml => @project, :status => :created, :location => @project }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
      end
    end
  end

  def edit
    @project = Project.find(params[:id])
  end
  def show
    @project = Project.find(params[:id])
#    @workpackage =Workpackage.new
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @user }
    end
  end
  def update
    @project = Project.find(params[:id])
    respond_to do |format|
      if @project.update_attributes(params[:project])
        format.html { redirect_to partner_projects_url(:notice => 'Project successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @project.errors, :status => :unprocessable_entity }
      end
    end
  end
end
